﻿using System;
using System.Collections.Generic;
namespace Liquid.Collections {
	/// <summary>
	/// A buffer that has the property that
	/// insertion and deletion are cheap, but
	/// only when done at the current position.
	/// </summary>
	/// <typeparam name="T">The type of items in the buffer</typeparam>
	public interface IBuffer<T> : IList<T> {
		/// <summary>
		/// Gets or sets the capacity of the buffer.
		/// </summary>
		/// <value>The capacity.</value>
		int Capacity { get; set; }
		/// <summary>
		/// Deletes a number of items from the buffer, after the current position.
		/// </summary>
		/// <param name="count">The number of items to delete.</param>
		void DeleteNext(int count);
		/// <summary>
		/// Deletes a number of items from the buffer, before the current position.
		/// </summary>
		/// <param name="count">The number of items to delete.</param>
		void DeletePrevious(int count);
		/// <summary>
		/// Inserts an item into the buffer at the current position.
		/// </summary>
		/// <param name="item">The item to insert.</param>
		void Insert(T item);
		/// <summary>
		/// Inserts a range of items into the buffer at the current position.
		/// </summary>
		/// <param name="from">The items to insert.</param>
		void InsertRange(IEnumerable<T> from);
		/// <summary>
		/// Gets or sets the current position.
		/// </summary>
		/// <value>The position.</value>
		int Position { get; set; }

		/// <summary>
		/// Gets the item directly before the current positon.
		/// </summary>
		/// <value>The item.</value>
		T Previous { get; }
		/// <summary>
		/// Gets the item directly after the current positon.
		/// </summary>
		/// <value>The item.</value>
		T Next { get; }

		/// <summary>
		/// Copies items from the buffer into an array.
		/// </summary>
		/// <param name="startIndex">The index in the buffer to start copying from.</param>
		/// <param name="array">The array to copy into.</param>
		/// <param name="arrayIndex">Index in the array to copy to.</param>
		/// <param name="count">The number of items to copy.</param>
		void CopyBuffer(int startIndex, T[] array, int arrayIndex, int count);

		/// <summary>
		/// Converts the buffer to an array
		/// </summary>
		/// <returns>An array containing the buffer's dats</returns>
		T[] ToArray();
	}
}
